/*
 * Copyright (C) 2021, All rights Reserved, Designed By
 * @author: maoyz
 * @Copyright: 2021-02-25 10:16  Inc. All rights reserved.
 */
package com.myz.cloud.stream.rocketmq.header.consumer;

import com.myz.cloud.stream.rocketmq.header.channel.IHeaderMessageChannel;
import com.myz.cloud.stream.rocketmq.header.producer.HeaderProducerManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

/**
 * @author maoyz
 */
@Component
public class HeaderMessageConsumer {

    private static final Logger log = LoggerFactory.getLogger(HeaderMessageConsumer.class);

    @StreamListener(value = IHeaderMessageChannel.HEADER_INPUT, condition = "headers['index']=='1'")
    public void receiveByHeader(Message msg) {
        log.info("filter by headers['index']=='1': {}", msg);
    }

    @StreamListener(value = IHeaderMessageChannel.HEADER_INPUT, condition = "headers['index']=='9999'")
    public void receivePerson(@Payload HeaderProducerManager.Person person) {
        log.info("Person: {}", person);
    }

    @StreamListener(value = IHeaderMessageChannel.HEADER_INPUT)
    public void receiveAllMsg(String msg) {
        log.info("receive allMsg by StreamListener. content: {}", msg);
    }
}